package com.lzm.flash;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

public class MsgActivity extends AppCompatActivity implements ChatMsgData.INotifyChatViewUpdata{

    private TextView m_msgViewName;
    private TextView m_onLine;
    ListView m_chatView;
    ArrayList<String> m_chatData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg);

        Intent inentArg=getIntent();
        m_msgViewName=((TextView)findViewById(R.id.msg_view_name));
        m_msgViewName.setText(inentArg.getStringExtra("name"));
        m_onLine=(TextView)findViewById(R.id.msg_view_online);
        m_onLine.setText("在线");

        m_chatView=(ListView)findViewById(R.id.msg_view_chat);

        m_chatData=new ArrayList<>();
        m_chatData.add("你好");
        m_chatData.add("在吗");
        m_chatData.add("三句话看你撒看见反抗撒酒疯凯撒回复可见");
        m_chatView.setAdapter(new chatViewAdapter());


    }

    @Override
    public void chatMsgUpdata() {

    }

    @Override
    public String getMac() {
        return null;
    }


    private class chatViewAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return m_chatData.size();
        }


        @Override
        public Object getItem(int position) {
            return m_chatData.get(position);
        }


        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView==null)
            {
                //注意    在fragment 中需要先获取 activity
                convertView=getLayoutInflater().inflate(R.layout.msg_chat_item_send,parent,false);
            }

            String data=(String)getItem(position);

            TextView v=(TextView)convertView.findViewById(R.id.msg_text);
            v.setText(data);
            return convertView;
        }
    }

    public void onBack(View view) {
        onBackPressed();
    }

    public void  onRefresh(View view){


    }
}
